import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SelectButton extends StatefulWidget {
  bool isSelected;
  String text;
  VoidCallback? onTap;

  SelectButton({this.isSelected = false, this.text = "选择按钮", this.onTap});

  @override
  State<StatefulWidget> createState() => _SelectButtonState();
}

class _SelectButtonState extends State<SelectButton> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 40.w,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4.w),
          color: widget.isSelected ? Color(0xffE1F4EE) : Color(0xffF5F5F5)),
      child: InkWell(
        onTap: () {
          if (widget.onTap != null) widget.onTap!();
        },
        child: Stack(
          alignment: AlignmentDirectional.bottomEnd,
          children: [
            Container(
              alignment: Alignment.center,
              child: Text(
                widget.text,
                style: TextStyle(
                  fontSize: 14.sp,
                  color:
                      widget.isSelected ? Color(0xff009669) : Color(0xff333333),
                ),
              ),
            ),
            Offstage(
              offstage: !widget.isSelected,
              child: Container(
                child: Image.asset(
                  "assets/images/icon_btn_selected.png",
                  width: 24.w,
                  height: 24.w,
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
